<!DOCTYPE html><html><head><title>Ext.ComponentQuery | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
<style type="text/css">.head-band { display: none; }
.header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
.doc-tab .members .member a.more { background-color: #efefef; }
</style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
</head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
<a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">

    req = {
        liveURL: '.',
        standAloneMode: true,
        origDocClass: 'Ext.ComponentQuery',
        docClass: 'Ext.ComponentQuery',
        docReq: 'Ext.ComponentQuery',
        version: '4.0',
        baseURL: '.',
        baseDocURL: '.',
        baseProdURL: '.'
    };

    clsInfo = {};



</script>

<script type="text/javascript" src="../search.js"></script>
<!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
<script type="text/javascript" src="../class_tree.js"></script>
<script type="text/javascript" src="../class_doc.js"></script>
<script type="text/javascript">
    req.source = 'ComponentQuery.html#Ext-ComponentQuery';
    clsInfo = {"methods":["query"],"cfgs":[],"properties":[],"events":[],"subclasses":[]};
    Ext.onReady(function() {
        Ext.create('Docs.classPanel');
    });
</script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/ComponentQuery.html#Ext-ComponentQuery" target="_blank">Ext.ComponentQuery</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>Provides searching of Components within <a href="Ext.ComponentManager.html" rel="Ext.ComponentManager" class="docClass">Ext.ComponentManager</a> (globally) or a specific
<a href="Ext.container.Container.html" rel="Ext.container.Container" class="docClass">Ext.container.Container</a> on the document with a similar syntax to a CSS selector.</p>

<p>Components can be retrieved by using their <a href="Ext.Component.html" rel="Ext.Component" class="docClass">xtype</a> with an optional . prefix</p>

<ul>
    <li>component or .component</li>
    <li>gridpanel or .gridpanel</li>
</ul>


<p>An itemId or id must be prefixed with a #</p>

<ul>
    <li>#myContainer</li>
</ul>


<p>Attributes must be wrapped in brackets</p>

<ul>
    <li>component[autoScroll]</li>
    <li>panel[title="Test"]</li>
</ul>


<p>Member expressions from candidate Components may be tested. If the expression returns a <i>truthy</i> value,
the candidate Component will be included in the query:</p>

<pre class="prettyprint"><code>var disabledFields = myFormPanel.query("{isDisabled()}");
</code></pre>


<p>Pseudo classes may be used to filter results in the same way as in <a href="Ext.DomQuery.html" rel="Ext.DomQuery" class="docClass">DomQuery</a>:<code></p>

<pre class="prettyprint">// Function receives array and returns a filtered array.
Ext.ComponentQuery.pseudos.invalid = function(items) {
    var i = 0, l = items.length, c, result = [];
    for (; i < l; i++) {
        if (!(c = items[i]).isValid()) {
            result.push(c);
        }
    }
    return result;
};

var invalidFields = myFormPanel.query('field:invalid');
if (invalidFields.length) {
    invalidFields[0].getEl().scrollIntoView(myFormPanel.body);
    for (var i = 0, l = invalidFields.length; i < l; i++) {
        invalidFields[i].getEl().frame("red");
    }
}
</pre>


<p></code></p>

<p>
Default pseudos include:<br />
- not
</p>


<p>Queries return an array of components.
Here are some example queries.</p>

<pre class="prettyprint"><code>    // retrieve all Ext.Panels in the document by xtype
    var panelsArray = Ext.ComponentQuery.query('panel');

    // retrieve all Ext.Panels within the container with an id myCt
    var panelsWithinmyCt = Ext.ComponentQuery.query('#myCt panel');

    // retrieve all direct children which are Ext.Panels within myCt
    var directChildPanel = Ext.ComponentQuery.query('#myCt > panel');

    // retrieve all gridpanels and listviews
    var gridsAndLists = Ext.ComponentQuery.query('gridpanel, listview');
</code></pre>


<p>For easy access to queries based from a particular Container see the <a href="Ext.container.Container.html#query" rel="Ext.container.Container#query" class="docClass">Ext.container.Container.query</a>,
<a href="Ext.container.Container.html#down" rel="Ext.container.Container#down" class="docClass">Ext.container.Container.down</a> and <a href="Ext.container.Container.html#child" rel="Ext.container.Container#child" class="docClass">Ext.container.Container.child</a> methods. Also see
<a href="Ext.Component.html#up" rel="Ext.Component#up" class="docClass">Ext.Component.up</a>.</p>
<div class="members"><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-query" class="member f ni"><a href="Ext.ComponentQuery.html#method-query" rel="method-query" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.ComponentQuery.html" class="definedIn docClass">Ext.ComponentQuery</a><br/><a href="../source/ComponentQuery.html#Ext-ComponentQuery-method-query" class="viewSource">view source</a></div><a name="query"></a><a name="method-query"></a><a href="Ext.ComponentQuery.html#" rel="method-query" class="cls expand">query</a>(
<span class="pre">Object component, Object selector</span>)
 : Boolean</div><div class="description"><div class="short"><p>Tests whether the passed Component matches the selector string.</p>
</div><div class="long"><p>Tests whether the passed Component matches the selector string.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">component</span> : Object<div class="sub-desc"><p>The Component to test</p>
</div></li><li><span class="pre">selector</span> : Object<div class="sub-desc"><p>The selector string to test against.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Boolean</span>&nbsp; &nbsp;<p>True if the Component matches the selector.</p>
</li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>